using System;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using WB.Mvc.Forms;

namespace WB.Mvc.Demo
{
	public class ModelFormCreationStrategy : IFormCreationStrategy
	{
		#region IFormCreationStrategy Members

		public FormBase Execute(Type formType, NameValueCollection form)
		{
			Type modelType = formType.GetGenericArguments().Single();

			var ctorArguments = new ArrayList();
			ctorArguments.Add(Activator.CreateInstance(modelType));

			if (form != null)
				ctorArguments.Add(form);

			return (FormBase) Activator.CreateInstance(formType, ctorArguments.ToArray());
		}

		#endregion
	}
}